#!/usr/bin/env python

import MySQLdb
import traceback

def test_mysql():
    db = MySQLdb.connect('127.0.0.1', 'root', '1q2w3e4r', 'python_mysql')
    cursor = db.cursor()
#    cursor.execute('select * from classmember5')
#    data = cursor.fetchone()
#    print data


# delete tables
#    cursor.execute("DROP TABLE IF EXISTS EMPLOYEE")
# 	sql = CREATE TABLE EMPLOYEE (
# 	     FIRST_NAME CHAR(20) NOT NULL,
# 	     LAST_NAME CHAR(20),
# 	     AGE INT,
# 	     SEX CHAR(1),
# 	     INCOME FLOAT);
#
    try:
        sql = """insert into EMPLOYEE(FIRST_NAME, LAST_NAME, AGE, SEX, INCOME) VALUES ('Mac', 'Mohan', 20, 'M', 2000)"""
        cursor.execute(sql)
        db.commit()	
        err_sql = """insertt into classmember5 values(5,'angmengxi', 1);"""
        cursor.execute(err_sql)
        db.commit()
    except:
        db.rollback()
        print traceback.format_exc()

    cursor.execute(sql)
    db.close()


if __name__ == '__main__':
    test_mysql()
